package neo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import neo.model.Hardware;
import neo.service.HardwareService;

@Controller
@RequestMapping("/hardware")
public class HardwareController {
	
	@Autowired
	private HardwareService hardwareService;
	
	@RequestMapping("/preSave")
	public ModelAndView preSave(@RequestParam(value="id",required=false)Integer id){
		ModelAndView mav = new ModelAndView();
		mav.addObject("hardware", hardwareService.loadById(id));
		mav.setViewName("hardware/save");
		return mav;
	}
	
	@RequestMapping("/save")
	public ModelAndView save(Hardware hardware){
		hardwareService.update(hardware);
		ModelAndView mav = new ModelAndView();
		mav.addObject("message", "保存成功！");
		mav.setViewName("hardware/saveOk");
		return mav;
	}

}
